import request from '@/utils/request'

// ========== 证书模板管理 ==========

// 分页查询证书模板
export function getTemplateList(currentPage, pageSize, queryParams) {
  return request({
    url: `/api/certificate/template/page/${currentPage}/${pageSize}`,
    method: 'get',
    params: queryParams
  })
}

// 根据类型获取模板列表
export function getTemplatesByType(templateType) {
  return request({
    url: `/api/certificate/template/type/${templateType}`,
    method: 'get'
  })
}

// 创建证书模板
export function createTemplate(templateData) {
  return request({
    url: '/api/certificate/template',
    method: 'post',
    data: templateData
  })
}

// 更新证书模板
export function updateTemplate(templateData) {
  return request({
    url: '/api/certificate/template',
    method: 'put',
    data: templateData
  })
}

// 设置默认模板
export function setAsDefault(templateId, templateType) {
  return request({
    url: `/api/certificate/template/${templateId}/default`,
    method: 'put',
    params: {
      templateType
    }
  })
}

// 删除证书模板
export function deleteTemplate(templateId) {
  return request({
    url: `/api/certificate/template/${templateId}`,
    method: 'delete'
  })
}

// ========== 证书生成管理 ==========

// 分页查询证书记录
export function getRecordList(currentPage, pageSize, queryParams) {
  return request({
    url: `/api/certificate/record/page/${currentPage}/${pageSize}`,
    method: 'get',
    params: queryParams
  })
}

// 生成参赛证书
export function generateParticipationCertificate(userId, projectId) {
  return request({
    url: '/api/certificate/generate/participation',
    method: 'post',
    params: {
      userId,
      projectId
    }
  })
}

// 生成获奖证书
export function generateAwardCertificate(userId, projectId, awardId, awardLevel) {
  return request({
    url: '/api/certificate/generate/award',
    method: 'post',
    params: {
      userId,
      projectId,
      awardId,
      awardLevel
    }
  })
}

// 生成志愿者证书
export function generateVolunteerCertificate(userId) {
  return request({
    url: '/api/certificate/generate/volunteer',
    method: 'post',
    params: {
      userId
    }
  })
}

// 生成裁判证书
export function generateRefereeCertificate(userId) {
  return request({
    url: '/api/certificate/generate/referee',
    method: 'post',
    params: {
      userId
    }
  })
}

// 批量生成证书
export function batchGenerateCertificates(params) {
  return request({
    url: '/api/certificate/generate/batch',
    method: 'post',
    params
  })
}

// 重新生成证书
export function regenerateCertificate(certificateId) {
  return request({
    url: `/api/certificate/regenerate/${certificateId}`,
    method: 'post'
  })
}

// 撤销证书
export function revokeCertificate(certificateId) {
  return request({
    url: `/api/certificate/revoke/${certificateId}`,
    method: 'put'
  })
}

// 下载证书
export function downloadCertificate(certificateId) {
  return request({
    url: `/api/certificate/download/${certificateId}`,
    method: 'get',
    responseType: 'blob'
  })
}

// 验证证书
export function validateCertificate(certificateNo) {
  return request({
    url: `/api/certificate/validate/${certificateNo}`,
    method: 'get'
  })
}

// 获取用户证书列表
export function getUserCertificates(userId) {
  return request({
    url: `/api/certificate/user/${userId}`,
    method: 'get'
  })
}

// 获取证书统计信息
export function getCertificateStatistics() {
  return request({
    url: '/api/certificate/statistics',
    method: 'get'
  })
}